Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: image loading handlers #6581

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

eatyourgreens
Copy link
Contributor

@eatyourgreens eatyourgreens commented Dec 18, 2024

Some changes to clean up image loading code, and speed up subject image loading.

  • lib-classifier: remove useEffect from useSubjectImage, so that image loading code runs on image load, rather than waiting for the next React render cycle.
  • lib-react-components: when there's no delay for useProgressiveImage, run the onLoad handler immediately, rather than waiting for the next event cycle.
  • refactor onLoad event handlers to use load events, rather than Image objects. This brings the event handlers in line with the DOM standard, and allows them to be attached directly to img elements.

Please request review from @zooniverse/frontend team or an individual member of that team.

Package

  • lib-classifier
  • lib-react-components

Linked Issue and/or Talk Post

How to Review

Image behaviour shouldn't have changed much in this PR, but the removal of the effect hooks, and the JS timeout, means that image onLoad handlers should run immediately, rather than waiting for the next React render cycle, or for the main browser thread to be free. That's probably not a big deal on a fast machine, but should make a difference to subject loading performance on slower devices.

Checklist

PR Creator - Please cater the checklist to fit the review needed for your code changes.
PR Reviewer - Use the checklist during your review. Each point should be checkmarked or discussed before PR approval.

General

  • Tests are passing locally and on Github
  • Documentation is up to date and changelog has been updated if appropriate
  • You can yarn panic && yarn bootstrap or docker-compose up --build and FEM works as expected
  • FEM works in all major desktop browsers: Firefox, Chrome, Edge, Safari (Use Browserstack account as needed)
  • FEM works in a mobile browser

General UX

Example Staging Project: i-fancy-cats

  • All pages of a FEM project load: Home Page, Classify Page, and About Pages
  • Can submit a classification
  • Can sign-in and sign-out
  • The component is accessible

Refactoring

  • The PR creator has described the reason for refactoring
  • The refactored component(s) continue to work as expected

@coveralls
Copy link

coveralls commented Dec 18, 2024

Coverage Status

coverage: 77.365% (+0.03%) from 77.338%
when pulling 3f561d1 on eatyourgreens:debug-subject-loading
into 51f064e on zooniverse:master.

Some changes to clean up image loading code, and speed up subject image loading.
- lib-classifier: remove `useEffect` from `useSubjectImage`, so that image loading code runs on image load, rather than waiting for the next React render cycle.
- lib-react-components: when there's no delay for `useProgressiveImage`, run the `onLoad` handler immediately, rather than waiting for the next event cycle.
- refactor `onLoad` event handlers to use `load` events, rather than `Image` objects. This brings the event handlers in line with the DOM standard.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants